package com.desyang.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import com.desyang.common.message.Request;
import com.desyang.common.message.Response;

public class IOClient {
    public static Object sendRequest(String host, int port, Request request) {
        try (
        Socket socket = new Socket(host, port);
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());) {
            oos.writeObject(request);
            oos.flush();
            Response response = (Response) ois.readObject();
            return response.getData();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
}
